package com.lzy.article.task;

import com.lzy.article.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;

@Configuration      //  1. 标记配置类注入容器
@EnableScheduling   //  2. 开启定时任务
public class TaskPublishArticles {

    @Autowired
    private ArticleService articleService;

    // 3. 添加定时任务
    @Scheduled(cron = "0/10 * * * * ?")
    private void publishArticle() {

        System.out.println("执行定时任务: " + LocalDateTime.now());
        // 4 修改文章定时状态改为即时状态
        articleService.updateAppointToPublish();
    }
}

